package com.qdu.group;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
//根据cat1分组统计购买量
public class GroupDriver {
    public static void main(String[] args) throws IOException {
        Configuration configuration=new Configuration();
        Job job=Job.getInstance(configuration,"average");
        job.setJarByClass(GroupDriver.class);

        job.setMapperClass(GroupMapper.class);
        job.setReducerClass(GroupReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        //configuration.set("fs.defaultFS", "hdfs://songchao/");
        FileInputFormat.addInputPath(job,new Path("hdfs://songchao:9000/data/mum_baby"));
        FileOutputFormat.setOutputPath(job, new Path("hdfs://songchao:9000/output/group"));
        try {
            boolean result = job.waitForCompletion(true);
            System.exit(result ? 0 : 1);
        } catch (InterruptedException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
